<?php
namespace App\Modules\Relationship\Models;


use App\Http\Services\CommonServices;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use App\Http\Model\Base;

class QueueExecModel extends Base {
    protected $table = "rs_queue_exec";
    protected $fields = ['id', 'body',
        'task','delay', 'state', 'code'
    ];

    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
    }

    public function insertRecord (array $data) {
        $insertData = array (
            'body'=>json_encode($data),
            'task'=>$data['taskname'],
            'delay'=>$data['delay'] ?? 0,
            'code'=>md5(json_encode($data))
        );
        DB::table($this->table)->insert($insertData);
    }

    public function updateRecordByCode ($code, $state) {
        return DB::table($this->table)->where(array('code'=>$code))->update(array('state'=>$state));
    }
}